package com.tensquare.recruit.service;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.tensquare.recruit.dao.RecruitDao;
import com.tensquare.recruit.pojo.Recruit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import util.IdWorker;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Service
public class RecruitService {
    @Autowired
    private IdWorker idWorker;
    @Autowired
    private RecruitDao recruitDao;
    public void save(Recruit recruit) {
        recruit.setId(idWorker.nextId()+"");
        recruitDao.insert(recruit);
    }

    public List<Recruit> findAll() {
        return recruitDao.selectList(null);

    }

    public Recruit findById(String recruitId) {
        return recruitDao.selectById(recruitId);
    }

    public void updateByRecruitId(Recruit recruit) {
        recruitDao.updateById(recruit);
    }

    public void deleteByRecruitId(String recruitId) {
        recruitDao.deleteById(recruitId);
    }

    public Page<Recruit> findByPage(Map<String, Object> map, Integer page, Integer size) {
        EntityWrapper<Recruit> wrapper=new EntityWrapper<>();
        Set<String> set=map.keySet();
        for (String s : set) {
            wrapper.eq(map.get(s)!=null,s,map.get(s));
        }
        Page<Recruit> page1=new Page<>(page,size);
        List<Recruit> recruits = recruitDao.selectPage(page1, wrapper);
        page1.setRecords(recruits);
        return page1;
    }

    public List<Recruit> findBySearch(Map<String, Object> map) {
        return recruitDao.selectByMap(map);
    }

    public Object recommend() {
        return recruitDao.recommend();
    }

    public Object newlist() {
        return recruitDao.newlist();

    }
}
